#pragma once
#include "threadmutex.h"

namespace Network
{
	class Guard
	{
	public:
		Guard(ThreadMutex &lock_) : owner(false)
		{
			lock = &lock_;
			lock->Acquire();
			owner = true;
		}

		~Guard(void)
		{
			if(owner)
				lock->Release();
		}

		void Acquire()
		{
			lock->Acquire();
			owner = true;
		}

		void Release()
		{
			lock->Release();
			owner = false;
		}

	private:
		ThreadMutex *lock;
		bool owner;
		Guard(const Guard &);
		void operator=(const Guard &);
	};
}